package com.xdjk.networkdemo;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;

import com.facebook.stetho.Stetho;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;
import com.xdjk.networkdemo.utils.NavigationController;

import me.yokeyword.fragmentation.Fragmentation;

/**
 * Created by zhanghs on 2017/8/16.
 */

public class XApplication extends Application {
    private static final String TagStr = "XDJK";
    private static XApplication mApplication;
    private static Context mContext;
    private static PackageInfo packInfo;

    @Override
    public void onCreate() {
        super.onCreate();
        this.mApplication = this;
        this.mContext = this;
        initConfig();
    }
    public static Context getInstance() {
        return mApplication;
    }

    public static Context getContext() {
        return mContext;
    }

    private void initConfig() {
        /*activity加入生命周期控制*/
        registerActivityLifecycleCallbacks(NavigationController.getInstance());
        initLogger();
        initStetho();
        initFragmentation();
    }

    private void initLogger() {
        FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(false)  // (Optional) Whether to show thread info or not. Default true
                .methodCount(0)         // (Optional) How many method line to show. Default 2
                .methodOffset(7)        // (Optional) Hides internal method calls up to offset. Default 5
                .tag(TagStr)   // (Optional) Global tag for every log. Default PRETTY_LOGGER
                .build();
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));

        Logger.d("debug");
        Logger.e("error");
        Logger.w("warning");
        Logger.v("verbose");
        Logger.i("information");
        Logger.wtf("wtf!!!!");
    }

    private void initStetho() {
        Stetho.initialize(
                Stetho.newInitializerBuilder(this)
                        .enableDumpapp(
                                Stetho.defaultDumperPluginsProvider(this))
                        .enableWebKitInspector(
                                Stetho.defaultInspectorModulesProvider(this))
                        .build());
    }

    private void initFragmentation() {
        // 栈视图功能，大大降低Fragment的开发难度，建议在Application里初始化
        Fragmentation.builder()
                // 显示悬浮球 ; 其他Mode:SHAKE: 摇一摇唤出   NONE：隐藏
                .stackViewMode(Fragmentation.BUBBLE)
                .install();
    }

}
